package org.ry.camera.adapter;
import java.util.List;

import org.ry.camera.bean.PretendBean;
import org.ry.camera.photoview.PhotoView;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout.LayoutParams;
/**
 * 
 * @author renyang
 *
 */
public class PopupAdapter extends PagerAdapter{
	
	private PhotoView currentView;
	
	private List<PretendBean> list ;
	
	public PopupAdapter(List<PretendBean> list){
		this.list = list;
	}
	
	@Override
	public int getCount() {
		return list.size();
	}
	
	public void setUpdateList(List<PretendBean> list){
		this.list = list;
	}
	
	@Override
	public View instantiateItem(ViewGroup container, int position) {
		PhotoView photoView = new PhotoView(container.getContext());
		PretendBean mPretendBean = list.get(position);
		photoView.setImageBitmap(mPretendBean.getmPic());
		// Now just add PhotoView to ViewPager and return it
		container.addView(photoView, LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);

		return photoView;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public void setPrimaryItem(ViewGroup container, int position,
			Object object) {
		currentView = (PhotoView) object;
	}

	public PhotoView getPrimaryItem() {
		return currentView;
	}
}
